package com.demo.bookstore.servlet;

import com.demo.bookstore.bean.Book;
import com.demo.bookstore.service.BookService;
import com.demo.bookstore.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author ddone
 * @date 2024/3/14-17:41
 */
@WebServlet("/index.html")
public class IndexServlet extends ViewBaseServlet {
    private BookService bookService = new BookServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        List<Book> bookList = bookService.findBookList();
        req.setAttribute("bookList",bookList);
        this.processTemplate("index",req,resp);
    }
}
